//货柜管理-格子列表
App.util.ns('Admin.Cabinet.Cell');
App.pages.add((function(){
    var NS = Admin.Cabinet.Cell;
    var page = new App.Page({
        name: 'cabinet/cell/index'
    });
    //页面初始化
    page.initStack.add('dataTable', function(){
        this.dataTable = new App.DataTable({
            baseUrl: '/admin/cabinet/cell',
            dataUrl: 'lists',
            table: {
                id: 'id',
                main: 0,
                showId: false,
                columns: App.util.copy(NS.Conf.columns)
            },
            filter: [
                {type: 'keywords'},
                {type: 'select', name: 'status', title: '状态', width: '120px', items: [
                    [0, '空闲'],
                    [1, '使用中'],
                    [2, '故障']
                ]}
            ],
            menu: [
                {parent: 'view', permission: 'op:admin.cabinet.cabinetCell.detail'},
                {parent: 'edit', permission: 'op:admin.cabinet.cabinetCell.update'},
                {type: 'inline', permission: 'op:admin.cabinet.cabinetCell.renting', name: '租用', 
                    operation: {type: 'change', url: 'renting'}, 
                    conditions: [['status', '0']]
                },
                {type: 'inline', permission: 'op:admin.cabinet.cabinetCell.rented', name: '归还', 
                    operation: {type: 'change', url: 'rented'}, 
                    conditions: [['status', '1']]
                },
                {type: 'inline', permission: 'op:admin.cabinet.cabinetCell.repair', name: '报修', 
                    operation: {type: 'change', url: 'repair'}, 
                    conditions: [['status', '1']]
                },
                {type: 'inline', permission: 'op:admin.cabinet.cabinetCell.replace', name: '修复', 
                    operation: {type: 'change', url: 'replace'}, 
                    conditions: [['status', '2']]
                },
                {parent: 'drop', permission: 'op:admin.cabinet.cabinetCell.delete'},
                {type: 'multi', name: '状态', openable: true, items: [
                    {type: 'multi', permission: 'op:admin.cabinet.cabinetCell.multiRenting', name: '租用', operation: {type: 'change', url: 'multiRenting', confirm: true}},
                    {type: 'multi', permission: 'op:admin.cabinet.cabinetCell.multiRented', name: '归还', operation: {type: 'change', url: 'multiRented', confirm: true}},
                    {type: 'multi', permission: 'op:admin.cabinet.cabinetCell.multiRepair', name: '报修', operation: {type: 'change', url: 'multiRepair', confirm: true}},
                    {type: 'multi', permission: 'op:admin.cabinet.cabinetCell.multiReplace', name: '修复', operation: {type: 'change', url: 'multiReplace', confirm: true}}
                    ], permission:[
                        'op:admin.cabinet.cabinetCell.multiReplace',
                        'op:admin.cabinet.cabinetCell.multiRepair',
                        'op:admin.cabinet.cabinetCell.multiRenting',
                        'op:admin.cabinet.cabinetCell.multiRented'
                ]},
                {parent: 'oplog', permission: 'op:admin.cabinet.cabinetCell.getOpLogs'}
            ],
            detail: {
                form: {
                    items: App.util.copy(NS.Conf.form)
                }
            }
        }, page);
        this.dataTable.fix(this.contentContainer);
    });
    //页面打开
    page.showStack.add('openPage', function(){
        if(this.params){
            var params = this.params;
            //设置面包屑导航
            this.setBreadcrumb([{
                icon: '<i class="fa fa-window-restore"></i>',
                content: '货柜与商品'
            }, {
                content: '货柜管理',
                action: function(){
                    App.nav.back();
                }
            }, {
                active: true,
                content: '格子管理 - ' + params['cabinet_name']
            }]);
            //设置参数
            for(var i in params){
                this.dataTable.param.set(i, params[i]);
            }
            if(this.dataTable.paginator){
                this.dataTable.paginator.currentPage = 1;
            }
            //加载数据
            this.dataTable.loadData();
        }
    });
    //页面刷新
    page.refreshStack.add('dataTable', function(){
        this.dataTable.loadData(true);
    });
    //页面销毁
    page.destroyStack.add('dataTable', function(){
        this.dataTable.destroy();
    });
    return page;
})());